<?php
class Category_model extends CI_Model{
	public function getCategoryByOffset($offset,$limit,$publish){
		$data = array();
		
		$lang = $this->lang->lang();
		
		$this->db->select('c.id, cl.category_name AS name, c.category_id_ref, c.image, c.order, c.public');
		$this->db->from('categories c');
		
		$this->db->limit($limit,$offset);
		$this->db->join('category_languages cl','cl.category_id = c.id');
		$this->db->join('languages l','l.id = cl.language_id AND l.code =\''.$lang. '\'');
		if($publish != -1)
			$this->db->where('c.public',$publish);
		
		$q = $this->db->get();
		$data = $q->result_array();
		$q->free_result();
		return $data;
	}
	
	public function getNumofCategory($publish){
		$data = 0;
		if($publish != -1)
			$this->db->where('public',$publish);
		$q = $this->db->get('categories');
		$data = $q->num_rows();
		$q->free_result();
		
		return $data;
	}
}